//
//  ZWMainViewController.swift
//  张伟的微博
//
//  Created by 伟 on 16/2/26.
//  Copyright © 2016年 伟. All rights reserved.
//

import UIKit

class ZWMainViewController: UITabBarController, ZWMainTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = ZWMainTabBar()
        mainTabBar.composeDelegate = self
        
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewControllers()
       
    }
    func addChildViewControllers(){
        let homeVc = ZWHomeTableViewController()
        addchildViewController(homeVc, title: "首页", imageName: "tabbar_home")
        let messageVc = ZWMessageTableViewController()
        addchildViewController(messageVc, title: "消息", imageName: "tabbar_message_center")
        //设置一个站位的tabbar
        addChildViewController(UIViewController())
        let discoverVc = ZWDiscoberTableViewController()
        addchildViewController(discoverVc, title: "发现", imageName: "tabbar_discover")
        let profileVc = ZWProfileTableViewController()
        addchildViewController(profileVc, title: "我", imageName: "tabbar_profile")
    }

    func addchildViewController(controller: UIViewController, title: String, imageName: String ) {
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        let hightImageName = imageName + "_highlighted"
        //选中后的颜色
        controller.tabBarItem.selectedImage = UIImage(named: hightImageName)
        //设置图片不要渲染
        controller.tabBarItem.selectedImage = UIImage(named: hightImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中文字的颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加为tabbar的自控制器，并且包装导航控制器
        addChildViewController(UINavigationController(rootViewController: controller))
        
    }
    //实现代理方法
    func mainTabBarComposeClick() {
        print("在 CZMainViewController 响应到了按钮的点击事件")
    }
   

}
